package pojo.weichatlab;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import cn.edu.bjtu.asyn.event.BuildModelEvet;
import cn.edu.bjtu.asyn.event.BuildWord2VecEvent;
import util.annotation.JspTableColumnName;
import util.annotation.JspTableEntity;

import java.util.Date;

@Entity
@Table(name="submitted_task")
@JspTableEntity
public class SubmittedTask extends WechatBaseModel {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY) 
	int id;
	String userid;
	/**
	 * 0 is Word2Vec
	 * 1 is LDA
	 * 2 is RNN
	 */
	@JspTableColumnName(colName="类型")
	int type;
	Date time;
	/**
	 * 0 is new
	 * 1 is running
	 * 2 is succeed
	 * 3 is failed
	 */
	int state;
	Date last_update;
	String path;
	
	public SubmittedTask(int id,int type,String username){
		this.id=id;
		this.type = type;
		this.userid = username;
		state = 0;
		time = new Date();
		last_update = new Date();
	}
	public SubmittedTask() {
		time = new Date();
		last_update = new Date();
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the userid
	 */
	public String getUserid() {
		return userid;
	}
	/**
	 * @param userid the userid to set
	 */
	public void setUserid(String userid) {
		this.userid = userid;
	}
	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}
	/**
	 * @return the time
	 */
	public Date getTime() {
		return time;
	}
	/**
	 * @param time the time to set
	 */
	public void setTime(Date time) {
		this.time = time;
	}
	/**
	 * @return the state
	 */
	public int getState() {
		return state;
	}
	/**
	 * @param state the state to set
	 */
	public void setState(int state) {
		this.state = state;
	}
	/**
	 * @return the last_update
	 */
	public Date getLast_update() {
		return last_update;
	}
	/**
	 * @param last_update the last_update to set
	 */
	public void setLast_update(Date last_update) {
		this.last_update = last_update;
	}
	/**
	 * @return the path
	 */
	public String getPath() {
		return path;
	}
	/**
	 * @param path the path to set
	 */
	public void setPath(String path) {
		this.path = path;
	}
	public static <T extends BuildModelEvet> SubmittedTask fromEvent(T t){
		int type = -1;
		if(t instanceof BuildWord2VecEvent){
			type = 0;
		}
		String username = t.getUserName();
		return new SubmittedTask(0,type,username);
	}
	
}
